package com.ship.service;


import java.util.Date;
import java.util.List;

import com.ship.control.search.ConditionPart;
import com.ship.control.search.SearchCond;
import com.ship.entity.FinalMaterial;
import com.ship.entity.MainlandMaterial;
import com.ship.entity.ShipDirectory;
import com.ship.entity.ShipInfo;
import com.ship.entity.ShipLog;
import com.ship.entity.ShipMaterial;
import com.ship.entity.ShopMaterial;

/**
 * 人员服务
 * @author wqf
 * @version  Nov 24, 2011 11:51:06 AM
 */
public class ShipService extends BaseService{
	//=============================船舶信息============
	public void editShipInfo(ShipInfo shipInfo){
		if(null==shipInfo.getId()){
			this.addShipInfo(shipInfo);
		}else{
			this.updateShipInfo(shipInfo);
		}
	}
	
	public void addShipInfo(ShipInfo shipInfo){
		shipInfo.setCreateDate(new Date());
		this.dao.saveObject(shipInfo);
	}
	
	
	public void updateShipInfo(ShipInfo shipInfo){
		this.dao.updateObject(shipInfo);
	}
		
	/**
	 * 删除（for dwr）
	 * @param id
	 */
	public void delShipInfoById(Long id){
		ShipInfo shipInfo=this.dao.loadObject(ShipInfo.class, id);
		this.dao.deleteObject(shipInfo);
	}
	
	
	/**
	 * 获取部门列表
	 * @param searchCond
	 * @return
	 */
	public List<ShipInfo> getShipInfoList(SearchCond searchCond){
		ConditionPart condPart = searchCond.getCondition();
		Object params[]=condPart.getParams().toArray(new Object[0]);
		List<ShipInfo> shipInfoList=this.dao.loadObjects(ShipInfo.class,condPart.getExpression(), "id", searchCond.getPageSize(), searchCond.getPageIndex(), params);
		return shipInfoList;
	}
	
	/**
	 * 获取 （for dwr）
	 * @param id
	 * @return
	 */
	public ShipInfo getShipInfoById(Long id){
		return this.dao.loadObject(ShipInfo.class, id);
	}
	
	
	//==============作业日志==============================================
	public void editShipLog(ShipLog shipLog){
		if(null==shipLog.getId()){
			this.addShipLog(shipLog);
		}else{
			this.updateShipLog(shipLog);
		}
	}
	
	public void addShipLog(ShipLog shipLog){
		shipLog.setCreateDate(new Date());
		this.dao.saveObject(shipLog);
	}
		
	public void updateShipLog(ShipLog shipLog){
		this.dao.updateObject(shipLog);
	}
	
	public void delShipLogById(Long id){
		ShipLog shipLog=this.dao.loadObject(ShipLog.class, id);
		this.dao.deleteObject(shipLog);
	}
	
	public List<ShipLog> getShipLogList(SearchCond searchCond){
		ConditionPart condPart = searchCond.getCondition();
		Object params[]=condPart.getParams().toArray(new Object[0]);
		List<ShipLog> shipLogList=this.dao.loadObjects(ShipLog.class,condPart.getExpression(), "id", searchCond.getPageSize(), searchCond.getPageIndex(), params);
		return shipLogList;
	}
	
	public ShipLog getShipLogById(Long id) {
		return this.dao.loadObject(ShipLog.class, id);
	}
	
	/////////////////////////////自购物料
	public ShopMaterial getShopMaterialById(Long id) {
		return this.dao.loadObject(ShopMaterial.class, id);		
	}
	
	public void editShopMaterial(ShopMaterial shopMaterial){
		if(null==shopMaterial.getId()){
			this.addShopMaterial(shopMaterial);
		}else{
			this.updateShopMaterial(shopMaterial);
		}
	}
	
	public void addShopMaterial(ShopMaterial shopMaterial){
		shopMaterial.setCreateDate(new Date());
		this.dao.saveObject(shopMaterial);
	}
		
	public void updateShopMaterial(ShopMaterial shopMaterial){
		this.dao.updateObject(shopMaterial);
	}
	
	public void delShopMaterialById(Long id){
		ShopMaterial shopMaterial=this.dao.loadObject(ShopMaterial.class, id);
		this.dao.deleteObject(shopMaterial);
	}
	public List<ShopMaterial> getShopMaterialList(SearchCond searchCond){
		ConditionPart condPart = searchCond.getCondition();
		Object params[]=condPart.getParams().toArray(new Object[0]);
		List<ShopMaterial> shopMaterialList=this.dao.loadObjects(ShopMaterial.class,condPart.getExpression(), "id", searchCond.getPageSize(), searchCond.getPageIndex(), params);
		return shopMaterialList;
	}
	/////////////////国内物料
	public MainlandMaterial getMainlandMaterialById(Long id) {
		return this.dao.loadObject(MainlandMaterial.class, id);
	}
	public void editMainlandMaterial(MainlandMaterial mainlandMaterial){
		if(null==mainlandMaterial.getId()){
			this.addMainlandMaterial(mainlandMaterial);
		}else{
			this.updateMainlandMaterial(mainlandMaterial);
		}
	}
	
	public void addMainlandMaterial(MainlandMaterial mainlandMaterial){
		mainlandMaterial.setCreateDate(new Date());
		this.dao.saveObject(mainlandMaterial);
	}
		
	public void updateMainlandMaterial(MainlandMaterial mainlandMaterial){
		this.dao.updateObject(mainlandMaterial);
	}
	
	public void delMainlandMaterialById(Long id){
		MainlandMaterial mainlandMaterial=this.dao.loadObject(MainlandMaterial.class, id);
		this.dao.deleteObject(mainlandMaterial);
	}
	
	public List<MainlandMaterial> getMainlandMaterialList(SearchCond searchCond){
		ConditionPart condPart = searchCond.getCondition();
		Object params[]=condPart.getParams().toArray(new Object[0]);
		List<MainlandMaterial> mainlandMaterialList=this.dao.loadObjects(MainlandMaterial.class,condPart.getExpression(), "id", searchCond.getPageSize(), searchCond.getPageIndex(), params);
		return mainlandMaterialList;
	}
	//////////////下船物料
	public FinalMaterial getFinalMaterialById(Long id) {
		return this.dao.loadObject(FinalMaterial.class, id);
	}
	public void editFinalMaterial(FinalMaterial finalMaterial){
		if(null==finalMaterial.getId()){
			this.addFinalMaterial(finalMaterial);
		}else{
			this.updateFinalMaterial(finalMaterial);
		}
	}
	
	public void addFinalMaterial(FinalMaterial finalMaterial){
		finalMaterial.setCreateDate(new Date());
		this.dao.saveObject(finalMaterial);
	}
		
	public void updateFinalMaterial(FinalMaterial finalMaterial){
		this.dao.updateObject(finalMaterial);
	}
	
	public void delFinalMaterialById(Long id){
		FinalMaterial finalMaterial=this.dao.loadObject(FinalMaterial.class, id);
		this.dao.deleteObject(finalMaterial);
	}
	
	public List<FinalMaterial> getFinalMaterialList(SearchCond searchCond){
		ConditionPart condPart = searchCond.getCondition();
		Object params[]=condPart.getParams().toArray(new Object[0]);
		List<FinalMaterial> finalMaterialList=this.dao.loadObjects(FinalMaterial.class,condPart.getExpression(), "id", searchCond.getPageSize(), searchCond.getPageIndex(), params);
		return finalMaterialList;
	}
	//单证目录
	public ShipDirectory getShipDirectoryById(Long id) {
		return this.dao.loadObject(ShipDirectory.class, id);
	}
	public void editShipDirectory(ShipDirectory shipDirectory){
		if(null==shipDirectory.getId()){
			this.addShipDirectory(shipDirectory);
		}else{
			this.updateShipDirectory(shipDirectory);
		}
	}
	
	public void addShipDirectory(ShipDirectory shipDirectory){
		shipDirectory.setCreateDate(new Date());
		this.dao.saveObject(shipDirectory);
	}
		
	public void updateShipDirectory(ShipDirectory shipDirectory){
		this.dao.updateObject(shipDirectory);
	}
	
	public void delShipDirectoryById(Long id){
		ShipDirectory shipDirectory=this.dao.loadObject(ShipDirectory.class, id);
		this.dao.deleteObject(shipDirectory);
	}
	
	public List<ShipDirectory> getShipDirectoryList(SearchCond searchCond){
		ConditionPart condPart = searchCond.getCondition();
		Object params[]=condPart.getParams().toArray(new Object[0]);
		List<ShipDirectory> shipDirectoryList=this.dao.loadObjects(ShipDirectory.class,condPart.getExpression(), "id", searchCond.getPageSize(), searchCond.getPageIndex(), params);
		return shipDirectoryList;
	}
	///////////////////////////////物料清单
	public ShipMaterial getShipMaterialById(Long id) {
		return this.dao.loadObject(ShipMaterial.class, id);		
	}
	
	public void editShipMaterial(ShipMaterial shipMaterial){
		if(null==shipMaterial.getId()){
			this.addShipMaterial(shipMaterial);
		}else{
			this.updateShipMaterial(shipMaterial);
		}
	}
	
	public void addShipMaterial(ShipMaterial shipMaterial){
		this.dao.saveObject(shipMaterial);
	}
		
	public void updateShipMaterial(ShipMaterial shipMaterial){
		this.dao.updateObject(shipMaterial);
	}
	
	public void delShipMaterialById(Long id){
		ShipMaterial shipMaterial=this.dao.loadObject(ShipMaterial.class, id);
		this.dao.deleteObject(shipMaterial);
	}
	public List<ShipMaterial> getShipMaterialList(SearchCond searchCond){
		ConditionPart condPart = searchCond.getCondition();
		Object params[]=condPart.getParams().toArray(new Object[0]);
		List<ShipMaterial> shipMaterialList=this.dao.loadObjects(ShipMaterial.class,condPart.getExpression(), "id", searchCond.getPageSize(), searchCond.getPageIndex(), params);
		return shipMaterialList;
	}
}
